package com.example.pc.adapterdemo.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.example.pc.adapterdemo.R;
import com.wx.wheelview.adapter.ArrayWheelAdapter;
import com.wx.wheelview.widget.WheelView;
import java.util.ArrayList;
import java.util.List;

public class WheelViewActivity extends AppCompatActivity {

    WheelView wheelView;
    private List<String> mList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wheelview);

        initData();
        initView();
    }

    private void initData() {
        mList.add("a1");
        mList.add("a2");
        mList.add("a3");
        mList.add("a4");
        mList.add("a5");
    }

    private void initView() {
        wheelView = (WheelView) findViewById(R.id.wheelview);
        wheelView.setWheelAdapter(new ArrayWheelAdapter(this)); // 文本数据源
        wheelView.setSkin(WheelView.Skin.Holo); // common皮肤
        wheelView.setWheelData(mList);  // 数据集合
        wheelView.setWheelSize(1);

        wheelView.setOnWheelItemSelectedListener(new WheelView.OnWheelItemSelectedListener() {
            @Override
            public void onItemSelected(int position, Object o) {
                String aa = (String) wheelView.getSelectionItem();
                Log.d("renchunlin", "onItemSelected: "+aa);
            }
        });
    }
}
